package com.skit.common.base;

import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.skit.common.R;
import com.skit.common.event.EventBusLifecycleObserver;
import com.skit.common.event.EventMessage;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//        new EventBusLifecycleObserver(this);
        Window window = getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//如果大于等于21（5.0）
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//是否大于等于6.0
                if (Build.VERSION.SDK_INT >= 27) {//是否大于等于8.1
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                } else {
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                    window.setNavigationBarColor(getResources().getColor(R.color.black));
                }
            } else {
                window.setNavigationBarColor(getResources().getColor(R.color.black));
                window.setStatusBarColor(getResources().getColor(R.color.statusColor));
            }
        }
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) finish();
        return super.onOptionsItemSelected(item);
    }

//    @Subscribe(threadMode = ThreadMode.MAIN)
//    protected void event(EventMessage eventMessage) {
//
//    }
}
